<?php
/**
 * Created by PhpStorm.
 * User: fangwei
 * Date: 2019-07-03
 * Time: 23:30
 */

namespace App\Http\Controllers\Admin\Api;


use App\Http\Controllers\Controller;
use App\Http\Repositories\Services\IClient;
use App\Http\Requests\Admin\ClientInputDTO;
use App\Http\Requests\Admin\ClientRemindInputDTO;
use App\Util\LayUiVo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;

class ClientController extends Controller
{
    protected $clientService;
    public function __construct(IClient $clientService)
    {
        $this->clientService = $clientService;
    }

    public function page(Request $request){
        $search = [];
        if ($request->get('name')) {
            $search['name'] = $request->get('name');
        }
        if ($request->get('mobile')) {
            $search['mobile'] = $request->get('mobile');
        }
        if ($request->get('user_name')) {
            $search['user_name'] = $request->get('user_name');
        }
        $dao = $this->clientService->lists($search, $request->get('page', 1), $request->get('limit','10'));
        return response()->json(new LayUiVo(['data'=>$dao,'message'=>Lang::get('response.success')]));
    }

    public function store(ClientInputDTO $inputDTO){
        $this->clientService->store($inputDTO);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success'),'jump'=>'/admin/clients']));
    }

    public function update(ClientInputDTO $inputDTO,$id){
        $this->clientService->update($inputDTO,$id);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success'),'jump'=>'/admin/clients']));
    }

    public function delete($id){
        $this->clientService->delete($id);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }

    public function remind($id,ClientRemindInputDTO $inputDTO){
        $this->clientService->remind($id,$inputDTO);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }

}